package net.maku.system.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.common.utils.Result;
import net.maku.system.convert.SysUserChargeConvert;
import net.maku.system.entity.SysUserChargeEntity;
import net.maku.system.service.SysUserChargeService;
import net.maku.system.query.SysUserChargeQuery;
import net.maku.system.vo.SysUserChargeVO;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import java.util.List;

/**
* 充值记录
*
* @author 小陈 
* @since 1.0.0 2025-03-19
*/
@RestController
@RequestMapping("system/charge")
@Tag(name="充值记录")
@AllArgsConstructor
public class SysUserChargeController {
    private final SysUserChargeService sysUserChargeService;

    @GetMapping("page")
    @Operation(summary = "分页")
    @PreAuthorize("hasAuthority('system:charge:page')")
    public Result<PageResult<SysUserChargeVO>> page(@ParameterObject @Valid SysUserChargeQuery query){
        PageResult<SysUserChargeVO> page = sysUserChargeService.page(query);
        return Result.ok(page);
    }

    @GetMapping("{id}")
    @Operation(summary = "信息")
    @PreAuthorize("hasAuthority('system:charge:info')")
    public Result<SysUserChargeVO> get(@PathVariable("id") Long id){
        SysUserChargeEntity entity = sysUserChargeService.getById(id);
        return Result.ok(SysUserChargeConvert.INSTANCE.convert(entity));
    }

    @PostMapping
    @Operation(summary = "保存")
    @PreAuthorize("hasAuthority('system:charge:save')")
    public Result<String> save(@RequestBody SysUserChargeVO vo){
        sysUserChargeService.save(vo);

        return Result.ok();
    }

    @PutMapping
    @Operation(summary = "修改")
    @PreAuthorize("hasAuthority('system:charge:update')")
    public Result<String> update(@RequestBody @Valid SysUserChargeVO vo){
        sysUserChargeService.update(vo);

        return Result.ok();
    }

//    @PutMapping
//    @Operation(summary = "修改")
//    @PreAuthorize("hasAuthority('system:sys_user_charge:update')")
//    public Result<String> update(@RequestBody @Valid SysUserChargeVO vo){
//        sysUserChargeService.update(vo);
//
//        return Result.ok();
//    }

    @DeleteMapping
    @Operation(summary = "删除")
    @PreAuthorize("hasAuthority('system:charge:delete')")
    public Result<String> delete(@RequestBody List<Long> idList){
        sysUserChargeService.delete(idList);

        return Result.ok();
    }
}